<?php if (!defined ( 'BASEPATH' )) exit ('No direct script access allowed');

/**
* 客户类
*/
class M_customer extends CI_Model
{
	const TBL_CUSTOMERS = 'customers'; 
    
	public function __construct()
	{
		parent::__construct();
	}
	
	public function insert($data){
	    //$data['password'] = md5($data['password']);
	    //$data['register_date'] = 'now()';
	    
	    //$this->db->insert(self::TBL_CUSTOMERS, $data);
	    
	    $sql = "insert into ".self::TBL_CUSTOMERS." (
	            customer_name,
	            email,
	            password,
	            register_date) values (
	            '".$data['customer_name']."',
	            '".$data['email']."',
	            '".md5($data['password'])."',
	            now())";
	    $this->db->query($sql);
	    $result = $this->db->affected_rows()==1 ? $this->db->insert_id() : FALSE;
	    return $result;
	}

	public function validate_customer($customer_email, $password)
	{
		$this->db->where('email', $customer_email);
		$this->db->where('password', md5($password));
		$this->db->limit(1);
		$query = $this->db->get('customers');
		
		if($query->num_rows() == 1){
		    $data = $query->row_array();
		}else{
		    $data = FALSE;
		}
		return $data;
	}
}

/* End of file m_customer.php */
/* Location: ./application/models/m_customer.php */